﻿using FS.Common.DotNetBean;
using FS.Common.DotNetCode;
using FS.Common.DotNetJson;
using FS.Common.DotNetUI;
using FS.Business;
using System;
using System.Data;
using System.Web;
using System.Web.SessionState;
using System.Text;

namespace FS.Web.BLL.Visa_Base
{
    /// <summary>
    /// Summary description for info
    /// </summary>
    public class info : IHttpHandler, IRequiresSessionState
    {
        private visa_dao _visa = new visa_dao();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Buffer = true;
            context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1.0);
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";
            string Action = context.Request["action"];           
            string cityid = context.Request["cityid"];
            string certtype = context.Request["certtype"];
            string ls_price = context.Request["cprice"];
            string ls_infoid = context.Request["infoid"];
            string ls_insertuser = context.Request["insert_user"];
            string ls_insertcard = context.Request["insert_cardno"];
            string ls_supplyid = context.Request["supplyid"];
            string ls_sprice = context.Request["sprice"];
            string ls_detailid = context.Request["detailid"];

            string text = Action;
            if (text != null)
            {
                if (text == "InsertInfoDetail")    //插入客户信息
                {
                    string ls = _visa.Check_InfoDetail(ls_infoid, ls_insertuser, cityid, certtype, ls_detailid);

                    if (string.IsNullOrEmpty(ls))
                    {
                        bool isok = _visa.InsertInfoDetail(ls_infoid, ls_insertuser, ls_insertcard, cityid, certtype, ls_price,
                            RequestSession.GetSessionUser().UserId.ToString(), RequestSession.GetSessionUser().UserName.ToString(),ls_detailid);
                        if (isok)
                        {
                            ls = "ok";
                        }
                        else
                        {
                            ls = "操作失败！";
                        }
                    }
                    else { 
                        //校验失败，返回sql校验信息
                    }

                    context.Response.Write(ls);
                    context.Response.End();
                }
                else if (text == "InsertInfoDetailWithSupply")    //插入客户信息
                {
                    string ls = _visa.Check_InfoDetail(ls_infoid, ls_insertuser, cityid, certtype, ls_detailid);

                    if (string.IsNullOrEmpty(ls))
                    {
                        bool isok = _visa.Ajax_InsertInfoDetail(ls_infoid, ls_insertuser, ls_insertcard, cityid, certtype, 
                            ls_price,ls_supplyid,ls_sprice,RequestSession.GetSessionUser().UserId.ToString(),
                            RequestSession.GetSessionUser().UserName.ToString(),ls_detailid);
                        if (isok)
                        {
                            ls = "ok";
                        }
                        else
                        {
                            ls = "操作失败！";
                        }
                    }
                    else
                    {
                        //校验失败，返回sql校验信息
                    }

                    context.Response.Write(ls);
                    context.Response.End();
                }
                else if (text == "DeleteInfo")    //删除客户信息
                {
                    System_Dao _sysdao = new System_Dao();
                    int Return = _sysdao.Virtualdelete("visa","visa_info", "info_id", ls_infoid.Split(','));
                    if (Return > 0)
                    {
                        Return = _sysdao.Virtualdelete("visa","visa_infodetail", "info_id", ls_infoid.Split(','));
                    }
                    context.Response.Write(Return.ToString());
                    context.Response.End();
                }
            }            
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}